Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AND-160] Make mentions color customisable (Compose) #5528

Merged
merged 3 commits into from
Dec 17, 2024

Conversation

VelikovPetar
Copy link
Contributor

🎯 Goal

Linear: https://linear.app/stream/issue/AND-160/customizing-text-color-for-user-mentions-in-android-compose-sdk
Makes the mentions color in the messages customisable, with a default value to what is currently used: StreamColors.primaryAccent.

🛠 Implementation details

  • Add new mentionColor property to MessageTheme
  • Add new mentionColor argument to the MessageTextFormatter.defaultFormatter and to the QuotedMessageTextFormatter.defaultFormatter with default value read from the appropriate message theme

🎨 UI Changes

Different mention color for own vs other message
custom-mention-colors

🧪 Testing

  1. Apply the provided patch
  2. Run the compose sample app
  3. Open a chat a make a new mention
  4. The mention should now have the color defined in ChatTheme.ownMessageTheme.mentionColor, and mentions by other users should have the color defined in ChatTheme.otherMessageTheme.mentionColor
Patch
Index: stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt b/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt
--- a/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt	(revision d6a32153979f36a54301925ccc8c86a021cd6fae)
+++ b/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt	(date 1734425981385)
@@ -54,6 +54,7 @@
 import androidx.compose.runtime.setValue
 import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.platform.LocalConfiguration
 import androidx.compose.ui.res.painterResource
 import androidx.compose.ui.unit.dp
@@ -148,11 +149,21 @@
     @Composable
     private fun SetupChatTheme() {
         val isInDarkMode = isSystemInDarkTheme()
-        val colors = if (isInDarkMode) StreamColors.defaultDarkColors() else StreamColors.defaultColors()
+        val colors = if (isInDarkMode) {
+            StreamColors.defaultDarkColors().copy(primaryAccent = Color.Red)
+        } else {
+            StreamColors.defaultColors().copy(primaryAccent = Color.Red)
+        }
         val typography = StreamTypography.defaultTypography()
         val shapes = StreamShapes.defaultShapes()
-        val messageComposerTheme = MessageComposerTheme.defaultTheme(isInDarkMode, typography, shapes, colors)
-        val ownMessageTheme = MessageTheme.defaultOwnTheme(isInDarkMode, typography, shapes, colors)
+        val messageComposerTheme = MessageComposerTheme
+            .defaultTheme(isInDarkMode, typography, shapes, colors)
+        val ownMessageTheme = MessageTheme
+            .defaultOwnTheme(isInDarkMode, typography, shapes, colors)
+            .copy(mentionColor = Color.Magenta)
+        val otherMessageTheme = MessageTheme
+            .defaultOtherTheme(isInDarkMode, typography, shapes, colors)
+            .copy(mentionColor = Color.Cyan)
         ChatTheme(
             isInDarkMode = isInDarkMode,
             colors = colors,
@@ -185,6 +196,7 @@
                 optionVisibility = MessageOptionItemVisibility(),
             ),
             ownMessageTheme = ownMessageTheme,
+            otherMessageTheme = otherMessageTheme,
         ) {
             SetupContent()
         }

@VelikovPetar VelikovPetar marked this pull request as ready for review December 17, 2024 10:54
@VelikovPetar VelikovPetar requested a review from a team as a code owner December 17, 2024 10:54
@JcMinarro JcMinarro enabled auto-merge (squash) December 17, 2024 12:50
@JcMinarro JcMinarro merged commit 7ca1e67 into develop Dec 17, 2024
9 checks passed
@JcMinarro JcMinarro deleted the feature/customizable-mentions-color branch December 17, 2024 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants